package com.leetcode.search.bfs;

import java.util.LinkedList;
import java.util.List;
import java.util.Queue;

/**
 * @author Dennis Li
 * @date 2020/7/25 20:14
 */
public class MaxDepth_559 {
    class Node {
        public int val;
        public List<Node> children;

        public Node() {
        }

        public Node(int _val) {
            val = _val;
        }

        public Node(int _val, List<Node> _children) {
            val = _val;
            children = _children;
        }
    }

    public int maxDepth(Node root) {
        if (root == null) return 0;
        Queue<Node> queue = new LinkedList<>();
        int level = 0;
        queue.offer(root);
        while (!queue.isEmpty()) {
            int size = queue.size();
            level++;
            while (size-- > 0)
                queue.poll().children.forEach(queue::offer);
        }
        return level;
    }

}
